package com.boyuan.huijiaoyu;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.boyuan.huijiaoyu.R;
import com.google.zxing.WriterException;
import com.zxing.encoding.EncodingHandler;

/**
 * 二维码名片
 * 
 * @author cheng
 * 
 */
public class QrBusinessCardActivity extends BaseActivity implements
		OnClickListener {

	private Button btnBack;
	private TextView txt_title;
	private ImageView iv_mycard_qrcode;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.qr_businesscard_activity);
		prepareView();
		prepareData();
	}

	private void prepareView() {
		btnBack = (Button) findViewById(R.id.btnBack);
		btnBack.setOnClickListener(this);
		txt_title = (TextView) findViewById(R.id.txt_title);
		txt_title.setText("二维码名片");
		iv_mycard_qrcode = (ImageView) findViewById(R.id.iv_mycard_qrcode);
	}

	private void prepareData() {

		generateCode("https://fir.im/colourpm");
		// account = SharePreferenceHelper.GetAccount(getApplicationContext());
		//
		// if (account != null) {
		//
		// // Display display = getWindowManager().getDefaultDisplay();
		// // int width = display.getWidth();
		//
		// generateCode("http://kakatool.com/wt/index.html?" +
		// account.getCid());
		// }

	}

	/**
	 * 获取二维码图片
	 * 
	 * @param code
	 */
	private void generateCode(String code) {
		Bitmap qrCodeBitmap = null;

		try {
			qrCodeBitmap = EncodingHandler.createQRCode(code, 250,
					EncodingHandler.WHITE);
		} catch (WriterException e) {
			e.printStackTrace();
		}

		if (qrCodeBitmap != null) {
			iv_mycard_qrcode.setImageBitmap(qrCodeBitmap);
		}
	}

	@Override
	public void backClicked() {
		// TODO Auto-generated method stub
		isBackAllowed = true;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.btnBack:
			finish();
			break;

		default:
			break;
		}
	}

}
